package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.domain.CapBac;
import com.tt.fashionWebSite.domain.PhanQuyen;
import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_MemberAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_MemberAccountController {
    @Autowired
    private Ad_MemberAccountService ad_memberAcountService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/AdMemberAccount", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminMemberAccount(HttpServletRequest request, @RequestBody PhanQuyenDto accountDto) {
        return new JsonResponseDto<Integer>(ad_memberAcountService.adminMemberAccount(accountDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllMemberCode", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ThongTinThanhVienDto>> getAllMemberCode(HttpServletRequest request) {
        return new JsonResponseDto<List<ThongTinThanhVienDto>>(ad_memberAcountService.getAllMemberCode(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getDataRegister", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<CapBacDto>> adminGetMemberLevel(HttpServletRequest request) {
        return new JsonResponseDto<List<CapBacDto>>(ad_memberAcountService.adminGetMemberLevel(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllAccount", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<PhanQuyenDto>> adminGetAllAccount(HttpServletRequest request) {
        return new JsonResponseDto<List<PhanQuyenDto>>(ad_memberAcountService.adminGetAllAccount(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllLevelInMember", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<CapBacDto>> getAllLevelInMember(HttpServletRequest request) {
        return new JsonResponseDto<List<CapBacDto>>(ad_memberAcountService.adminGetMemberLevel(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toMemberAccountPage/{maTV}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageProductCategory(HttpServletRequest request, @PathVariable String maTV, Map<String, Object> map) throws ParseException {
        map.put("maTV", maTV);
        return new ModelAndView("admin/ad-member-account-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editMemberAccount", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<PhanQuyenDto> getMemberAccountInfoEdit(HttpServletRequest request, @RequestBody PhanQuyenDto accountDto) {
        return new JsonResponseDto<PhanQuyenDto>(ad_memberAcountService.getMemberAccountInfoEdit(accountDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerAccountEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<PhanQuyenDto> registerMemberAccountEdit(HttpServletRequest request, @RequestBody PhanQuyenDto accountDto) {
        return new JsonResponseDto<PhanQuyenDto>(ad_memberAcountService.registerMemberAccountEdit(accountDto), JsonResponseCode.SUCCESS);
    }
}